home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / What's New? / Tool Chest / Memory Monitor / MemoryMonitor.vu < prev    next >
Encoding:
Text File  |  1993-08-13  |  12.0 KB  |  498 lines  |  [TEXT/MPS ]

  1. Libraries "MemoryMonitor.vulib";
  2.  
  3. #######################################################################################
  4. #    MemoryMonitor Example Script
  5. #
  6. # • What's this script do?
  7. #    This script demonstrates the Memory Monitor V.U. external tool.
  8. #
  9. # • Where will Memory Monitor run?
  10. #    If a target is assigned to the user within the V.U. document,
  11. #    then the script will expect Memory Monitor to be on the Target.
  12. #
  13. #    If the V.U. document has no target assigned,
  14. #    then the script will expect Memory Monitor to be on the Host.
  15. #
  16. #######################################################################################
  17. Script    MemoryMonitorExample()
  18. Begin
  19.         ###    These flags control the verbosity & beauty of printed output.
  20.         ###    All flags true yields more and formatted output.
  21.     global TraceToolCalls        := true;
  22.     global ReportSuccess        := true;
  23.     global FormattedOutput        := true;
  24.     
  25.         ###    Initialize Memory Monitor either on the Host, or the Target
  26.     OnTheTarget := match[ target ];
  27.     x := InitMemoryMonitor( OnTheTarget );
  28.  
  29.         ###    Demonstrate each available service
  30.     x := GetProcessInfo( 'Finder' ); 
  31.  
  32.         ###    Quit Memory Monitor
  33.      x := QuitMemoryMonitor();
  34.         
  35. end;
  36.  
  37. #######################################################################################
  38. Task CallEachService()
  39. Begin
  40.  
  41.         ###    Call each Memory Monitor service
  42.         ###    Exit with error code, if an error is encountered
  43.         
  44.     x := Demo_GetToolVersion();                     
  45.     
  46.     x := Demo_GetToolServices();                    
  47.     
  48.     x := Demo_ServiceSupported( 'GetToolVersion' ); 
  49.     
  50.     x := Demo_GetProcessInfo( 'Memory Monitor' );     
  51.  
  52.     x := Demo_GetAllProcesses();                     
  53.     
  54.     x := Demo_GetZoneMap( 'MultiFinderZone' );         
  55.     
  56.     x := Demo_GetZoneTotals( 'SystemZone' );         
  57.     
  58.     x := Demo_CheckZone( 'Memory Monitor' );         
  59.  
  60.     x := Demo_GetAboutThisMacintosh();                 
  61.     
  62.     x := Demo_ReadBytes();                             
  63.  
  64.     x := Demo_MacsbugCmd( "HT" );                    
  65.  
  66. end;
  67.  
  68. #######################################################################################
  69. Task Demo_GetToolVersion()
  70. Begin
  71.     
  72.     if global TraceToolCalls
  73.     begin
  74.         Println;
  75.         Println "———————————————————————————————————————    GetToolVersion";
  76.     end;
  77.     
  78.     x := MemoryMonitor( 'GetToolVersion' );
  79.     if x[1] = 0
  80.     begin
  81.         if global ReportSuccess
  82.         begin
  83.             Println x[2];
  84.         end;
  85.     end;
  86.     else
  87.     begin
  88.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  89.     end;
  90. end;
  91.  
  92. #######################################################################################
  93. Task Demo_GetToolServices()
  94. Begin
  95.     if global TraceToolCalls
  96.     begin
  97.         Println;
  98.         Println "———————————————————————————————————————    GetToolServices";
  99.     end;
  100.  
  101.     x := MemoryMonitor( 'GetToolServices' );
  102.     if x[1] = 0
  103.     begin
  104.         if global ReportSuccess
  105.             Println x[2];
  106.     end;
  107.     else
  108.     begin
  109.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  110.     end;
  111. end;
  112.  
  113. #######################################################################################
  114. Task Demo_ServiceSupported( SrvcName )
  115. Begin
  116.     if global TraceToolCalls
  117.     begin
  118.         Println;
  119.         Println "———————————————————————————————————————    ServiceSupported";
  120.     end;
  121.  
  122.     x := MemoryMonitor( 'ServiceSupported', SrvcName );
  123.     if x[1] = 0
  124.     begin
  125.         if global ReportSuccess
  126.             Println x[2];
  127.     end;
  128.     else
  129.     begin
  130.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  131.     end;
  132. end;
  133.  
  134. #######################################################################################
  135. Task Demo_GetAllProcesses()
  136. Begin
  137.     if global TraceToolCalls
  138.     begin
  139.         Println;
  140.         Println "———————————————————————————————————————    GetAllProcesses";
  141.     end;
  142.  
  143.     x := GetAllProcesses();
  144.     if x[1] = 0
  145.     begin
  146.         if global ReportSuccess
  147.         begin
  148.             if global FormattedOutput
  149.                 PrintProcessMap( x[2] );
  150.             else
  151.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  152.         end;
  153.     end;
  154.     else
  155.     begin
  156.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  157.     end;
  158. end;
  159.  
  160. #######################################################################################
  161. Task Demo_GetProcessInfo( ProcessName )
  162. Begin
  163.     if global TraceToolCalls
  164.     begin
  165.         Println;
  166.         Println "———————————————————————————————————————    GetProcessInfo";
  167.     end;
  168.  
  169.     x := GetProcessInfo( ProcessName );
  170.     if x[1] = 0
  171.     begin
  172.         if global ReportSuccess
  173.         begin
  174.             if global FormattedOutput
  175.                 PrintProcessInfo( x[2] );
  176.             else
  177.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  178.         end;
  179.     end;
  180.     else
  181.     begin
  182.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  183.     end;
  184. end;
  185.  
  186. #######################################################################################
  187. Task Demo_GetZoneMap( ZoneSelector )
  188. Begin
  189.     if global TraceToolCalls
  190.     begin
  191.         Println;
  192.         Println "———————————————————————————————————————    GetZoneMap : {ZoneSelector}";
  193.     end;
  194.  
  195.     x := GetZoneMap( ZoneSelector );
  196.     if x[1] = 0
  197.     begin
  198.         if global ReportSuccess
  199.         begin
  200.             if global FormattedOutput
  201.                 PrintZoneMap( x[2], ZoneSelector );
  202.             else
  203.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  204.         end;
  205.     end;
  206.     else
  207.     begin
  208.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  209.     end;
  210.     return x[1];
  211. end;
  212.  
  213. #######################################################################################
  214. Task Demo_GetZoneTotals( ZoneSelector )
  215. Begin
  216.     if global TraceToolCalls
  217.     begin
  218.         Println;
  219.         Println "———————————————————————————————————————    GetZoneTotals : {ZoneSelector}";
  220.     end;
  221.  
  222.     x := GetZoneTotals( ZoneSelector );
  223.     if x[1] = 0
  224.     begin
  225.         if global ReportSuccess
  226.         begin
  227.             if global FormattedOutput
  228.                 PrintZoneTotals( x[2], ZoneSelector );
  229.             else
  230.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  231.         end;
  232.     end;
  233.     else
  234.     begin
  235.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  236.     end;
  237.     return x[1];
  238. end;
  239.  
  240. #######################################################################################
  241. Task Demo_CheckZone( ZoneSelector )
  242. Begin
  243.     if global TraceToolCalls
  244.     begin
  245.         Println;
  246.         Println "———————————————————————————————————————    CheckZone : {ZoneSelector}";
  247.     end;
  248.  
  249.     x := CheckZone( ZoneSelector );
  250.     if    x[1] = 0 and TypeOf( x[2] ) = 'symbol'
  251.     begin
  252.         if global ReportSuccess
  253.         begin
  254.             if global FormattedOutput
  255.                 Println "Zone Ok - ", ZoneSelector;
  256.             else
  257.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  258.         end;        
  259.     end;
  260.     else
  261.     begin
  262.         if global FormattedOutput
  263.             Println "Zone Corrupt - ", ZoneSelector;
  264.         else
  265.             Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  266.     end;
  267.     return x[1];
  268. end;
  269.  
  270. #######################################################################################
  271. Task Demo_GetAboutThisMacintosh()
  272. Begin
  273.     if global TraceToolCalls
  274.     begin
  275.         Println;
  276.         Println "———————————————————————————————————————    GetAboutThisMacintosh";
  277.     end;
  278.  
  279.     x := GetAboutThisMacintosh();
  280.     if x[1] = 0
  281.     begin
  282.         if global ReportSuccess
  283.         begin
  284.             if global FormattedOutput
  285.                 PrintAboutThisMacintosh( x[2] );
  286.             else
  287.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  288.         end;        
  289.     end;
  290.     else
  291.     begin
  292.         Println "DoGetAboutThisMacintosh";
  293.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  294.     end;
  295. end;
  296.  
  297. #######################################################################################
  298. Task Demo_ReadBytes()
  299. Begin
  300.     if global TraceToolCalls
  301.     begin
  302.         Println;
  303.         Println "———————————————————————————————————————    ReadBytes";
  304.     end;
  305.  
  306.         ###    Read the low global 'CurApName', 
  307.         ###    which contains the current application name
  308.     x := ReadBytes( { 0, 2320 }, 32 );
  309.     if x[1] = 0
  310.     begin
  311.         if global ReportSuccess
  312.         begin
  313.             if TypeOf( x[2] ) = 'list'
  314.             begin
  315.                     ### Assemble the bytes into a string and then print
  316.                 s := "";
  317.                 for i := 2 to x[2][1] + 1
  318.                     s := s + CodeToCharacter( x[2][i] );
  319.                 Println "Application Name ( CurApName ) = '", s, "'";
  320.             end;
  321.         end;        
  322.     end;
  323.     else
  324.     begin
  325.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  326.     end;
  327. end;
  328.  
  329. #######################################################################################
  330. Task Demo_MacsbugCmd( CmdLine )
  331. Begin
  332.     if global TraceToolCalls
  333.     begin
  334.         Println;
  335.         Println "———————————————————————————————————————    MacsbugCmd";
  336.     end;
  337.     
  338.     x := MacsbugCmd( CmdLine );
  339.     if x[1] = 0
  340.     begin
  341.         if global ReportSuccess
  342.         begin
  343.             Println "MacsbugCmd : '", CmdLine, "'";
  344.             Println "Result     : ", x[2];
  345.         end;
  346.     end;
  347.     else
  348.     begin
  349.         Println "MacsbugCmd : '", CmdLine, "'  Result : ", x[2];
  350.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  351.     end;
  352. end;
  353.  
  354. #######################################################################################
  355. Task PrintProcessMap( pMap )
  356. Begin
  357.     for each P in pMap
  358.     begin
  359.         PrintProcessInfo( P );    
  360.     end;            
  361. end;
  362.  
  363. #######################################################################################
  364. Task PrintProcessInfo( P )
  365. Begin
  366.     Println;
  367.     Println "Name        - ", P[1];
  368.     Println "Type        - ", P[2];
  369.     Println "Signature   - ", P[3];
  370.     Println "Location    - ", RightJustify( P[4], 12 );
  371.     Println "Size        - ", RightJustify( P[5], 12 );
  372.     Println "Free Memory - ", RightJustify( P[6], 12 );
  373. end;
  374.  
  375. #######################################################################################
  376. Task PrintZoneMap( pMap, pZoneID, Label := "", Indent := "" )
  377. Begin
  378.     if Label = ""
  379.     begin
  380.         Println; 
  381.         Println "Zone                       First         Last          Size in";
  382.         Println "Specifier                  Address       Address       Bytes";
  383.         Println "---------                  -------       -------       -------";
  384.  
  385.         if TypeOf( pZoneID ) = 'list'
  386.             For each i in pZoneID
  387.             begin
  388.                 if TypeOf( i ) = 'integer'
  389.                 begin
  390.                     i := NumToStr( i );
  391.                 end;
  392.                 
  393.                 if Card Label > 0
  394.                     Label := Label + ", " + i;
  395.                 else
  396.                     Label := i;
  397.             end;
  398.         else
  399.         begin
  400.             Label := pZoneID;
  401.         end;
  402.     end;
  403.     
  404.     Println LeftJustify( Label, 20 ), 
  405.             Indent,
  406.             RightJustify( pMap[1], 14 ), 
  407.             RightJustify( pMap[2], 14 ), 
  408.             RightJustify( pMap[3], 14 );
  409.  
  410.     if TypeOf( pMap[4] ) = 'list'
  411.     begin
  412.         Index := 1;
  413.         for each Z in pMap[4]
  414.         begin
  415.             PrintZoneMap( Z, pZoneID, Label + "," + RightJustify( NumToStr( Index ), 2), Indent + "   " );
  416.             Index := Index + 1;
  417.         end;            
  418.     end;
  419. end;
  420.  
  421. #######################################################################################
  422. Task PrintZoneTotals( T, ZoneID := "" )
  423. Begin
  424.     Println "Zone Totals for : ", ZoneID;
  425.     Println "                        Blocks       Bytes";
  426.     Println "                        ------       -----";
  427.     Println "Free                  - ", RightJustify( NumToStr( T[1][1] ), 7 ), ", ", RightJustify( T[1][2], 11 );
  428.     Println "NonRelocatable        - ", RightJustify( NumToStr( T[2][1] ), 7 ), ", ", RightJustify( T[2][2], 11 );
  429.     Println "Relocatable           - ", RightJustify( NumToStr( T[3][1] ), 7 ), ", ", RightJustify( T[3][2], 11 );
  430.     Println "  Locked              - ", RightJustify( NumToStr( T[4][1] ), 7 ), ", ", RightJustify( T[4][2], 11 );
  431.     Println "  Purgable & Unlocked - ", RightJustify( NumToStr( T[5][1] ), 7 ), ", ", RightJustify( T[5][2], 11 );
  432.     Println "Total                 - ", RightJustify( NumToStr( T[6][1] ), 7 ), ", ", RightJustify( T[6][2], 11 );
  433. end;
  434.  
  435. #######################################################################################
  436. Task PrintAboutThisMacintosh( pAbout )
  437. Begin
  438.     Println "Built-in Memory      - ", RightJustify( pAbout[1], 10 ), "K";
  439.     Println "Total Memory         - ", RightJustify( pAbout[2], 10 ), "K";
  440.     Println "Largest Unused block - ", RightJustify( pAbout[3], 10 ), "K";
  441.     if (not IsUndefined( pAbout[4] )) and Card pAbout[4] > 1
  442.     begin
  443.         For each appInfo in pAbout[4]
  444.         begin
  445.             Println "  ", LeftJustify( appInfo[1], 32 ), " - ", RightJustify( appInfo[2], 10 ), "K";
  446.         end;
  447.     end;
  448. end;
  449.  
  450. #######################################################################################
  451. Task RightJustify( TStr, FieldWidth )
  452. begin
  453.     PadStr := "";
  454.     L := Card TStr;
  455.     if L < FieldWidth
  456.     begin
  457.         PadLength := FieldWidth - L;
  458.         L := (PadLength - Card PadStr) / 8;
  459.         for i := 1 to L 
  460.             PadStr := PadStr + "        ";
  461.  
  462.         If PadLength - Card PadStr >= 4
  463.             PadStr := PadStr + "    ";
  464.  
  465.         If PadLength - Card PadStr >= 2
  466.             PadStr := PadStr + "  ";
  467.  
  468.         If PadLength - Card PadStr >= 1
  469.             PadStr := PadStr + " ";
  470.     end;
  471.     return PadStr + TStr;
  472. end;
  473.  
  474. #######################################################################################
  475. Task LeftJustify( TStr, FieldWidth )
  476. begin
  477.     PadStr := "";
  478.     L := Card TStr;
  479.     if L < FieldWidth
  480.     begin
  481.         PadLength := FieldWidth - L;
  482.         L := (PadLength - Card PadStr) / 8;
  483.         for i := 1 to L 
  484.             PadStr := PadStr + "        ";
  485.  
  486.         If PadLength - Card PadStr >= 4
  487.             PadStr := PadStr + "    ";
  488.  
  489.         If PadLength - Card PadStr >= 2
  490.             PadStr := PadStr + "  ";
  491.  
  492.         If PadLength - Card PadStr >= 1
  493.             PadStr := PadStr + " ";
  494.     end;
  495.     return TStr + PadStr;
  496. end;
  497.  
  498.